﻿using LiuJinYuDataGridView.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LiuJinYuDataGridView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //for (int i = 0; i < 10; i++)
            //{
            //    #region 通过索引添加数据行
            //    //// 添加一个新行并返回新行的索引(第一行索引从0开始)
            //    //int myNewRowIndex = dataGridView1.Rows.Add();
            //    //dataGridView1.Rows[myNewRowIndex].Cells["Column2"].Value = "First";
            //    //dataGridView1.Rows[myNewRowIndex].Cells["Column3"].Value = "的暗调" + i;
            //    //dataGridView1.Rows[myNewRowIndex].Cells["Column7"].Value = "移除";
            //    #endregion

            //    #region 直接创建单元格列的方法
            //    //DataGridViewRow dgvr = new DataGridViewRow();

            //    //DataGridViewCheckBoxCell dgvck = new DataGridViewCheckBoxCell();
            //    //dgvck.ToolTipText = "00" + i;
            //    ////dgvck.Value = true;
            //    //dgvr.Cells.Add(dgvck);

            //    //DataGridViewTextBoxCell dgvtbx = new DataGridViewTextBoxCell();
            //    //dgvtbx.Value = "姓名" + i;
            //    //dgvr.Cells.Add(dgvtbx);

            //    //dataGridView1.Rows.Add(dgvr);
            //    #endregion
            //}


            // 添加4行,直接操作DataGridView的单元格进行添加
            dataGridView1.Rows.Add(4);
            dataGridView1.Rows[0].Cells[1].Value = "tangsen";
            dataGridView1.Rows[0].Cells[2].Value = "Leader";
            dataGridView1.Rows[0].Cells[3].Value = "一心向佛";
            dataGridView1.Rows[0].Cells[4].Value = "http://www.baidu.com";

            // 获取资源图片
            Image myimg = Resources.古风_古装_唐僧 as Image;
            // 将图片缩小为原来的1/2
            Bitmap mybm = new Bitmap(myimg.Width / 3, myimg.Height / 3);
            // 加载到画布上
            Graphics mygh = Graphics.FromImage(mybm);
            // 设置为高质量缩放
            mygh.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            // 绘制缩放后的图片
            //mygh.DrawImage(myimg, 0, 0, myimg.Width / 3, myimg.Height / 3);
            mygh.DrawImage(myimg, 0, 0, mybm.Width, mybm.Height);
            // 释放画布资源
            mygh.Dispose();

            dataGridView1.Rows[0].Cells[5].Value = mybm;
            dataGridView1.Rows[0].Cells[6].Value = "移除";

            dataGridView1.Rows[1].Cells[1].Value = "sunwukong";
            dataGridView1.Rows[1].Cells[2].Value = "老二";
            dataGridView1.Rows[1].Cells[3].Value = "急躁";
            dataGridView1.Rows[1].Cells[4].Value = "http://www.baidu.com";
            dataGridView1.Rows[1].Cells[5].Value = Resources.孙悟空;
            dataGridView1.Rows[1].Cells[6].Value = "移除";

            dataGridView1.Rows[2].Cells[1].Value = "bajie";
            dataGridView1.Rows[2].Cells[2].Value = "老三";
            dataGridView1.Rows[2].Cells[3].Value = "肥胖";
            dataGridView1.Rows[2].Cells[4].Value = "http://www.baidu.com";
            dataGridView1.Rows[2].Cells[5].Value = Resources.猪八戒;
            dataGridView1.Rows[2].Cells[6].Value = "移除";

            dataGridView1.Rows[3].Cells[1].Value = "shaseng";
            dataGridView1.Rows[3].Cells[2].Value = "Leader";
            dataGridView1.Rows[3].Cells[3].Value = "忠诚";
            dataGridView1.Rows[3].Cells[4].Value = "http://www.baidu.com";
            dataGridView1.Rows[3].Cells[5].Value = Resources.沙僧;
            dataGridView1.Rows[3].Cells[6].Value = "移除";

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            // 这里的列是"移除"按钮所在的列
            if (e.ColumnIndex == 6)
            {
                dataGridView1.Rows.RemoveAt(e.RowIndex);
            }
            else if (e.ColumnIndex == 4) // 链接列
            {
                string linkVal = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                process1.StartInfo.FileName = linkVal;
                process1.Start();
            }
        }
    }
}
